@extends('layouts.app')

@section('content')
    <div id="app">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">重置密码</div>

                <div class="panel-body">
                    <form class="form-horizontal" id="form" role="form" method="POST" action="{{ url('admin/password/reset') }}">
                        {{ csrf_field() }}

                        <div class="form-group">
                            <label for="email" class="col-md-4 control-label">当前密码</label>

                            <div class="col-md-6">
                                <input type="password" class="form-control" name="password_old" v-model="password_old" autofocus>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="password" class="col-md-4 control-label">新密码</label>

                            <div class="col-md-6">
                                <input type="password" class="form-control" v-model="password" name="password">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="password-confirm" class="col-md-4 control-label">确认新密码</label>
                            <div class="col-md-6">
                                <input type="password" class="form-control" v-model="password_confirmation" name="password_confirmation">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <a class="btn btn-primary" v-on:click="submit()">
                                    重置密码
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                password_old: '',
                password: '',
                password_confirmation: ''
            },
            methods: {
                submit: function(){
                    if(!this.password || !this.password_confirmation || !this.password_old){
                        alert('请补全信息！');
                        return false;
                    }
                    if(this.password !== this.password_confirmation){
                        alert('两次密码不一致！');
                        return false;
                    }
                    document.getElementById('form').submit();
                }
            }
        });
    </script>
@endsection